package org.jieshen.m1.d1;

class Solution {
    public int[][] construct2DArray(int[] original, int m, int n) {
        int[][] arr = new int[m][n];
        if (original.length != m * n)
            return new int[0][0];

        for (int i = 0; i < original.length; i++) {
            arr[i / n][i % n] = original[i];
        }
        return arr;
    }

    public static void main(String[] args) {
        int[] original = {0,1,2,3,4,5,6,7};
        int[][] array = new Solution().construct2DArray(original, 2, 4);
        for (int[] arr : array) {
            for (int a : arr) {
                System.out.print(a+",");
            }
            System.out.println();
        }

    }
}